<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<c:if test="${code==1}">
	<form id="pagerForm" method="post"
		action="orderCountByDaySearchAction.action?toResult=searchOrderCountByDay&rightId=${rightId}">
		<input type="hidden" name="pageNum" value="${page.currentPage }" /> <input
			type="hidden" name="pageSize" value="${page.pageSize }" />
	</form>

	<form id="searchOrderCountByDayFormBar"
		onsubmit="return navTabSearch(this);"
		action="orderCountByDaySearchAction.action?toResult=searchOrderCountByDay&rightId=${rightId}"
		method="post">
		<div class="pageHeader">
			<input type="hidden" name="init" value=0>
			<div class="searchBar">
				<table class="searchContent">
					<tr>
						<td>日期：</td>
						<td><input type="text" class="date" name="count_day"
							value="${count_day}" /></td>
						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td>
							<div class="buttonActive">
								<div class="buttonContent">
									<button type="submit">检索</button>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td>日期：</td>
						<td><input type="text" class="date" id="countDayInputId" /></td>
						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td>
							<div class="buttonActive">
								<div class="buttonContent">
									<button type="button" onclick="countOneDayOrder()">统计指定日期</button>
								</div>
							</div>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<div class="pageContent">
			<table class="list" width="100%" layoutH="138">
				<thead>
					<tr>
						<th align="center">日期</th>
						<th align="center">订单总量</th>
						<th align="center">自取件订单量</th>
						<th align="center">系统流水收入</th>
			<!-- 			<th align="center">线上支付收入</th> -->
						<th align="center">优惠券总额</th>
					</tr>
				</thead>
				<tbody>
					<tr style="background-color:#99FF99;color:red;">
						<th width="5%" align="center">所有日期总和</th>
						<th width="5%" align="center"><s:property
								value="#request.totalAllOrderNum" /></th>
						<th width="5%" align="center"><s:property
								value="#request.totalRabbitOrderNum" /></th>
						<th width="5%" align="center"><span style="color:red">￥</span><s:property
								value="#request.totalPriceOrderNum" /></th>
<%-- 						<th width="5%" align="center"><span style="color:red">￥</span><s:property
								value="#request.totalPayOrderNum" /></th> --%>
						<th width="5%" align="center"><span style="color:red">￥</span><s:property
								value="#request.totalgiftMoney_count" /></th>
					</tr>
					<s:iterator var="dayCount" value="page.data" status="st">
						<tr target="sid_support" rel="<s:property value="#dayCount.id" />">
							<th width="5%" align="center"><s:date
									name="#dayCount.count_day" format='yyyy-MM-dd' /></th>
							<th width="5%" align="center"><s:property
									value="#dayCount.total_count" /></th>
							<th width="5%" align="center"><s:property
									value="#dayCount.rabbit_count" /></th>
							<th width="5%" align="center">￥<s:property
									value="#dayCount.total_price" /></th>
<%-- 							<th width="5%" align="center">￥<s:property
									value="#dayCount.total_pay" /></th> --%>
							<th width="5%" align="center">￥<s:property
									value="#dayCount.giftMoney_count" /></th>
						</tr>
					</s:iterator>
				</tbody>
			</table>
			<div class="panelBar">
				<div class="pages">
					<span>共${page.totalNum }条，共${page.totalPage }页</span>
				</div>
				<div class="pagination" targetType="navTab"
					totalCount="${page.totalNum }" numPerPage="${page.pageSize }"
					pageNumShown="10" currentPage="${page.currentPage }"></div>
			</div>
		</div>
	</form>
</c:if>
<c:if test="${code==0}">
	${message}
</c:if>


<script type="text/javascript">
		
	/**
	 * 统计指定日期
	 */
	function countOneDayOrder(){
		var day =$("#countDayInputId").val();  //输入框的日期
		if(""==day){
			alertMsg.error('请选择日期！');
			return;
		}
		//判断系统日期是否大于输入框日期，大于则表示统计当天以前日期的数据，可统计，否则不可统计
		var now = new Date();
		var nowtime = now.getFullYear()+"-"+((now.getMonth()+1)<10?"0":"")+(now.getMonth()+1)+"-"+(now.getDate()<10?"0":"")+now.getDate();//JS获取当前系统日期
		var nowTimStamp = getDateTime(nowtime);
		var inputTime = getDateTime(day);
		if(inputTime>nowTimStamp){
			alertMsg.error("只能统计当日之前数据！");
			return;
		}
		$.ajax( {
	        type : 'post',
	        url : "<%=basePath%>addOneDayOrderCountAction.action",
			data : {
				count_day : day
			},
			success : function(data) {
				if (data == "true") {
					alertMsg.correct("统计成功！");
					$("#searchOrderCountByDayFormBar").submit();
				} else if (data == "exist") {
					alertMsg.error("已经存在该日期记录！");
				} else {
					alertMsg.error("统计失败！");
				}
			}
		});
	}

	// "2015-02-03" 转换为时间戳
	function getDateTime(str) {
		return new Date(str.replace(/-/g, '/')).getTime();
	}
</script>


